home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
tcpevent.c
< prev
next >
Wrap
Text File
|
1992-04-17
|
10KB
|
404 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#include "netevent.h"
#include "hostform.h"
#include "NCSAfuncs.h" /* must follow hostform.h */
#pragma segment 3270tcp
extern char tcpinitok; /* network code is active */
extern unsigned char * rcvbuff;
extern short rcvmax;
void tcpevent(void)
{
static unsigned long * Ticks = (unsigned long *)0x16a;
int ev, what, data;
short cnt, i, j;
OSErr rc;
cnr *cp;
short kindex;
unsigned long klimit;
CursHandle watchHandle;
char waitcur;
myStask();
ev = Sgetevent(USERCLASS | ERRCLASS | CONCLASS, &what, &data);
if (ev) {
sprintf(dbgmsg, "event = %d, class = %d, data = %d", ev, what, data);
putln(dbgmsg);
switch(what) {
case CONCLASS:
cp = port_to_cp(data);
if (cp == 0) break;
switch(ev) {
case CONOPEN:
if (cp->connstate == 3) {
cp->connstate = 4;
cp->online = 1;
cp->kblcode = 2;
if (cp->myWindow == 0) {
rc = createwindow(cp);
if (rc != noErr) {
tcplgout(0, cp);
}
}
else {
newstat(cp);
}
/* if the session was opened by the api, we
delay registering the session until data
is received. (See telnet.c) */
if (!(cp->apiopenpend)) {
apiregister(1, cp);
}
if (cp->serverconn) {
cp->servermode = 0;
srvswitch(cp);
if (!(cp->logon)) {
if (cp->kblock) {
cp->kblock = 0;
newstat(cp);
}
cp->hadascii = 1;
return;
}
}
}
break;
case CONDATA:
cnt = netread(data, rcvbuff+64, rcvmax);
myStask();
if (cnt == 0) break;
if (cnt < 0) {
closeresponse(closeNetFail, cp);
tcplgout(1, cp);
break;
}
if (cp->logon) {
cp->wr_active = 1;
newstat(cp);
}
while (cnt > 0) {
telrcv(rcvbuff+64, cnt, cp);
myStask();
cnt = netread(data, rcvbuff+64, rcvmax);
myStask();
}
if (cp->wr_active && (!(cp->needwrite))) {
cp->wr_active = 0;
newstat(cp);
}
/* 3270 mode */
if (cp->fsinv && (cp->data_init == 1)) {
cp->fsinv = 0;
invldscr(cp);
if (cp->pndbeep) {
cp->pndbeep = 0;
myStask(); /* beep takes a while */
beep(cp);
myStask();
}
}
/* line mode */
else if (cp->logon == 0) {
if (cp->pndbeep) {
cp->pndbeep = 0;
myStask(); /* beep takes a while */
beep(cp);
myStask();
}
}
if (cnt < 0) {
closeresponse(closeNetFail, cp);
tcplgout(1, cp);
}
break;
case CONCLOSE:
closeresponse(closeNetClose, cp);
tcplgout(1, cp);
break;
case CONFAIL:
if (cp->connstate == 3) {
stoperr(conalrt, cp);
cp->connstate = 0;
cp->kblcode = 4;
if (cp->apiopen) {
apiopenerr(openConnFailed, cp);
}
removeconnection(cp);
}
break;
default:
break;
}
break;
case USERCLASS:
switch(ev) {
case DOMOK:
cp = port_to_cp(data);
if (cp == 0) break;
if (cp->connstate != 2) break;
cp->mp = Slooknum(data);
if (cp->mp == 0) {
putln("Slooknum failed!");
stoperr(topnalrt, cp);
cp->connstate = 0;
cp->kblcode = 4;
if (cp->apiopen) {
apiopenerr(openConnFailed, cp);
}
removeconnection(cp);
break;
}
sprintf(dbgmsg, "address for %s is %d.%d.%d.%d",
(cp->mp)->hname, (cp->mp)->hostip[0],
(cp->mp)->hostip[1], (cp->mp)->hostip[2],
(cp->mp)->hostip[3]);
putln(dbgmsg);
cp->myport = Snetopen(cp->mp, rdportnum(cp));
if (cp->myport < 0) {
putln("Snetopen failed!");
stoperr(topnalrt, cp);
cp->connstate = 0;
cp->kblcode = 4;
if (cp->apiopen) {
apiopenerr(openConnFailed, cp);
}
removeconnection(cp);
break;
}
cp->connstate = 3;
break;
case DOMFAIL:
cp = port_to_cp(data);
if (cp == 0) break;
if (cp->connstate != 2) break;
stoperr(numalrt, cp);
cp->connstate = 0;
cp->kblcode = 4;
if (cp->apiopen) {
apiopenerr(openResFailed, cp);
}
removeconnection(cp);
break;
case FTPCOPEN:
ftpcopen = 1;
ftpnewstat();
putln("FTP control connection opened");
break;
case FTPCLOSE:
ftpcopen = 0;
ftpnewstat();
putln("FTP control connection closed");
break;
case FTPBEGIN:
ftpdopen = 1;
ftpnewstat();
putln("FTP data connection opened");
break;
case FTPEND:
ftpdopen = ftplopen = 0;
ftpnewstat();
putln("FTP data or list connection closed");
break;
case FTPLIST:
ftplopen = 1;
ftpnewstat();
putln("FTP list connection opened");
break;
case FTPUSER:
putln("FTP user name entered");
break;
case FTPPWOK:
putln("FTP password verified");
break;
case FTPPWNO:
putln("FTP password failed");
break;
case RCPBEGIN:
putln("rcp transfer begin");
break;
case RCPEND:
putln("rcp transfer ended");
break;
default:
putln("received unknown user class event");
break;
}
break;
case ERRCLASS:
NetError(data);
break;
case ICMPCLASS:
putln("received ICMP event (should never happen)");
break;
case SCLASS:
putln("received session event (should never happen)");
break;
default:
putln("received event with unknown class");
break;
}
myStask();
}
for (j=0; j < MAXSESSIONS; j++) {
cp = cplist[j];
if (cp != 0) {
if (cp->tcpflg) {
kindex = 0;
klimit = (*Ticks) + 15;
waitcur = 0;
if (cp->pasteactive == 0) {
while ((cp->kbqsize > 0) && (!(cp->kblock))) {
if (cp->vmxbgn && (!(cp->vmxsub))) break;
if (cp->pasteactive) break;
if (((cp->kbqueue)[kindex].shift) == 100) {
cp->pasteactive = 1;
}
else {
hndkbd((cp->kbqueue)[kindex].code,
(cp->kbqueue)[kindex].shift, cp);
}
kindex++;
cp->kbqsize--;
if ((*Ticks) > klimit) {
myStask();
klimit = (*Ticks) + 15;
if (waitcur == 0) {
watchHandle = GetCursor(4);
SetCursor(*watchHandle);
waitcur = 1;
dfltcurs = 2;
}
}
}
if ((cp->kbqsize > 0) && (kindex > 0)) {
for (i = 0; i < cp->kbqsize; i++) {
(cp->kbqueue)[i].code = (cp->kbqueue)[i+kindex].code;
(cp->kbqueue)[i].shift = (cp->kbqueue)[i+kindex].shift;
}
}
}
else { /* pasteactive true */
while ((cp->pastebuffsize > 0) && (!(cp->kblock))) {
if (cp->vmxbgn && (!(cp->vmxsub))) break;
hndkbd((cp->pastebuff)[kindex], 99, cp);
kindex++;
cp->pastebuffsize--;
if ((*Ticks) > klimit) {
myStask();
klimit = (*Ticks) + 15;
if (waitcur == 0) {
watchHandle = GetCursor(4);
SetCursor(*watchHandle);
waitcur = 1;
dfltcurs = 2;
}
}
}
if ((cp->pastebuffsize > 0) && (kindex > 0)) {
for (i = 0; i < cp->pastebuffsize; i++) {
(cp->pastebuff)[i] = (cp->pastebuff)[i+kindex];
}
}
if (cp->pastebuffsize == 0) {
cp->pasteactive = 0;
DisposPtr(cp->pastebuff);
cp->pastebuff = 0;
if (cp->pastebeep) beep(cp);
newwrite(cp);
newcur(cp);
}
}
}
}
}
}
void myStask(void)
{
if (tcpinitok) {
Stask();
if (ftpcopen || ftpdopen || ftplopen) {
rftpd(0);
}
}
}
cnr *port_to_cp(int port)
{
short i;
cnr *cp;
for (i=0; i < MAXSESSIONS; i++) {
cp = cplist[i];
if (cp != 0) {
if (cp->tcpflg && (cp->connstate > 0) && (cp->myport == port)) {
return(cp);
}
}
}
sprintf(dbgmsg, "no connection record found for port %d", port);
putln(dbgmsg);
return(0);
}
void ftpnewstat(void)
{ /* newstat for all windows */
short i;
cnr *cp;
for (i=0; i < MAXSESSIONS; i++) {
cp = cplist[i];
if (cp != 0) {
if (cp->myWindow != 0) {
newstat(cp);
}
}
}
}